/**
  ******************************************************************************
  * @file    RS485_Driver.c
  * @author  tuancheng_Zero
  * @version V0.1
  * @date    08/05/2024
  * @brief   RS485 Driver
  ******************************************************************************
*/ 
#ifndef  __RS485_DRIVER_H__
#define  __RS485_DRIVER_H__

#ifdef __cplusplus
extern "C" {
#endif

// RS485中断配置
#define RS485_IRQn               UART4_IRQn
#define RS485_IRQHandler 		 UART4_IRQHandler

// RS485串口配置
#define RS485_UART              UART4
#define RS485_GPIO              GPIOC
#define RS485_CLK               RCC_APB1_PERIPH_UART4
#define RS485_GPIO_CLK          RCC_APB2_PERIPH_GPIOC
#define RS485_RxPin             GPIO_PIN_11
#define RS485_TxPin             GPIO_PIN_10
#define RS485_DMA_DR_Base       ((uint32_t)&UART4->DAT)

// RS485DMA配置
#define RS485_DMA               DMA2
#define RS485_DMA_Rx_IRQn       DMA2_Channel3_IRQn
#define RS485_DMA_Tx_IRQn       DMA2_Channel5_IRQn
#define RS485_Tx_DMA_Channel    DMA2_CH5
#define RS485_Tx_DMA_FLAG       (DMA2_FLAG_GL5|DMA2_FLAG_TC5|DMA2_FLAG_TE5|DMA2_FLAG_HT5)
#define RS485_Rx_DMA_Channel    DMA2_CH3
#define RS485_Rx_DMA_FLAG       (DMA2_FLAG_GL3|DMA2_FLAG_TC3|DMA2_FLAG_TE3|DMA2_FLAG_HT3)  
#define RS485_Tx_DMA_Function   DMA2_Channel5_IRQHandler
#define RS485_Rx_DMA_Function   DMA2_Channel3_IRQHandler

void RS485_Init(void);
uint8_t RS485_DmaTransferData(uint8_t * pData, uint16_t length);

#ifdef __cplusplus
}
#endif
#endif   /*   __EXTEND_PRIMEMOTOR_DRIVER_H__   */
